﻿namespace Bll.Systems
{
    using IDal.Systems;
    using Model.Systems;
    using System;
    using System.Data;
    using System.IO;
    using System.Net;
    using System.Net.NetworkInformation;
    using System.Reflection;
    using DALFactory;
    public class NewsBll
    {
        private static readonly INews dal = DataAccess.CreateNews();

        public static void Add(NewsEnt model)
        {
            dal.Add(model);
        }

        public static void Delete(int ID)
        {
            dal.Delete(ID);
        }

        public static DataTable GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }

        public static int GetMaxId(string swhere)
        {
            return dal.GetMaxId(swhere);
        }

        public static NewsEnt GetModel(int ID)
        {
            return dal.GetModel(ID);
        }

        public static DataTable GetPageList(int PageSize, int PageIndex, string strWhere)
        {
            return dal.GetPageList(PageSize, PageIndex, strWhere);
        }

        public static void Update(NewsEnt model)
        {
            dal.Update(model);
        }

        public static bool UpdateYeJieDongTai()
        {
            try
            {
                Ping ping = new Ping();
                PingReply reply = null;
                try
                {
                    reply = ping.Send("www.teaxt.com", 0xbb8);
                    if ((reply == null) || ((reply != null) && (reply.Status != IPStatus.Success)))
                    {
                        return false;
                    }
                    if (reply.Status == IPStatus.Success)
                    {
                    }
                }
                catch (Exception)
                {
                }
                WebClient client = new WebClient();
                string fileName = "news";
                string str2 = Directory.GetParent(Assembly.GetExecutingAssembly().Location) + "//" + fileName;
                string requestUriString = "http://www.teaxt.com/Down/news";
                string path = str2 + fileName;
                try
                {
                    WebRequest request = WebRequest.Create(requestUriString);
                }
                catch
                {
                }
                try
                {
                    client.DownloadFile(requestUriString, fileName);
                    FileStream input = new FileStream(fileName, FileMode.Open, FileAccess.Read);
                    byte[] buffer = new BinaryReader(input).ReadBytes((int) input.Length);
                    FileStream stream2 = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write);
                    stream2.Write(buffer, 0, (int) input.Length);
                    stream2.Close();
                }
                catch
                {
                    return false;
                }
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
}

